class EasingToTouch extends egret.DisplayObjectContainer {
    private ball:Ball
    private easing:number = 0.1
    private targetX:number = 0
    private targetY:number = 0

    public constructor() {
        super()
        this.once( egret.Event.ADDED_TO_STAGE, this.onAddToStage, this)
    }

    private onAddToStage(event:egret.Event) {
        this.targetX = this.stage.stageWidth / 2
        this.targetY = this.stage.stageHeight / 2
        this.ball = new Ball()
        this.addChild(this.ball)
        this.ball.x = 0
        this.ball.y = 0
        this.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.trackTouch, this)
        this.addEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this)
    }

    private onEnterFrame(event:egret.Event) {
        this.ball.x += (this.targetX - this.ball.x) * this.easing
        this.ball.y += (this.targetY - this.ball.y) * this.easing
    }

    private trackTouch(evt:egret.TouchEvent) {
        this.targetX = evt.stageX
        this.targetY = evt.stageY
    }
}